<?php
namespace app\index\model;
use think\Model;
use think\Db;
class Sendmessage1 extends Model
{
	public static $target = "http://106.ihuyi.cn/webservice/sms.php?method=Submit";
	//生成验证码
	public function createCode($length = 6 , $numeric = 0)
	{
		if($numeric) {
			$hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1));
		} else {
			$hash = '';
			$chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz';
			$max = strlen($chars) - 1;
			for($i = 0; $i < $length; $i++) {
				$hash .= $chars[mt_rand(0, $max)];
			}
		}
			return $hash;
	}
	//发送post,返回数组
	public function sendPost($curlPost)
	{
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, self::$target);
		curl_setopt($curl, CURLOPT_HEADER, false);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_NOBODY, true);
		curl_setopt($curl, CURLOPT_POST, true);
		curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
		$xml = curl_exec($curl);
		curl_close($curl);
		$arr = xml_to_array($xml);
		return $arr;
	}
}